package com.obas.business.analogy.util;

import com.ease.common.util.Detect;
import com.obas.business.analogy.vo.AnalogyContextParam;
import com.obas.model.type.AnalogyDimensionType;
import com.obas.model.type.ProcessDimensionType;
import com.obas.model.type.TimeDimensionType;

public abstract class AnalogyTableNameUtil extends Detect {

	public static final String BASE_TABLE_PREFIX = "S";
	
	public static final String ANALOGY_TABLE_PREFIX = "X";

	public static final String SPERATOR = "_";

	//S_
	public static final String baseTableName(ProcessDimensionType processDimensionType) {
		String tableName = BASE_TABLE_PREFIX + SPERATOR +  processDimensionType.getTablePart();

		return oracleName(tableName);
	}
	
	public static final String tableName(AnalogyContextParam analogyContextParam) {
		return tableName(analogyContextParam.getAnalogyDimensionType(), analogyContextParam.getTimeDimensionType(), analogyContextParam.getProcessDimensionType());
	}

	public static final String tableName(AnalogyDimensionType analogyDimensionType, TimeDimensionType timeDimensionType, ProcessDimensionType processDimensionType) {
		String tableName = ANALOGY_TABLE_PREFIX + SPERATOR + analogyDimensionType.getTablePart() + SPERATOR + timeDimensionType.getTablePart() + SPERATOR + processDimensionType.getTablePart();

		return oracleName(tableName);
	}

	public static final String sequenceName(String tableName) {
		return oracleName("SEQ_" + tableName);
	}

	public static final int ORACLE_NAME_MAX_LENGTH = 30;

	private static final String oracleName(String string) {
		if (null != string && string.length() > ORACLE_NAME_MAX_LENGTH) {
			return string.substring(0, ORACLE_NAME_MAX_LENGTH);
		}
		return string;
	}

}
